package com.easy.controller;

import com.easy.service.ImageCleanupService;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/image")
@CrossOrigin
public class ImageCleanupController {

    @Autowired
    private ImageCleanupService imageCleanupService;

    /**
     * 手动触发清理未使用的图片
     * @return 操作结果
     */
    @PostMapping("/cleanup")
    public Result cleanupUnusedImages() {
        try {
            imageCleanupService.cleanupUnusedImages();
            return Result.success("清理未使用的图片完成");
        } catch (Exception e) {
            return Result.fail(500,  e.getMessage());
        }
    }
}
